import { GetServerSideProps, NextPage, PageConfig } from 'next';
import Head from 'next/head';
import { useEffect, useState } from 'react';
import Content from './content';
import { Query as Q1 } from '../../api/teachjd/xsxk/content/query.api';
import { tbclass } from '../../../atoms/db';

interface IProps {
	query: Q1
	classs: Pick<ITbclass, 'grade' | 'classname'>[]
}

/**
 * 学生选课
 */
const Page: NextPage<IProps> = ({ query, classs }) => {
	return (
		<>
			<Head>
				<title>学生选课</title>
			</Head>
			<Content ints={query} classs={classs} />
		</>
	);
};

export const config: PageConfig = {
	amp: false
};

export default Page;

export const getServerSideProps: GetServerSideProps<IProps> = async (context) => {
	const query = context.query as Record<string, string>;
	const classs = await tbclass()
		.select('grade', 'classname')
		.groupBy('grade', 'classname')
		.orderBy('grade', 'asc')
		.orderBy('classname', 'asc');
	return {
		props: {
			classs,
			query: {
				page: query.page || '1',
				pagesize: '10',
				q: query.q || ''
			}
		}
	};
};
